package com.gy.smartmanagement.service;

import android.app.IntentService;
import android.content.Intent;
import android.os.Bundle;

import com.gy.smartmanagement.base.api.bean.ErrorResultBean;
import com.gy.smartmanagement.base.api.rx.SchedulersCompat;
import com.gy.smartmanagement.base.app.AppApplication;
import com.gy.smartmanagement.login.LoginActivity;
import com.gy.smartmanagement.login.api.LoginApiService;
import com.gy.smartmanagement.login.mvp.LoginBean;
import com.gy.smartmanagement.utils.ConstanceValue;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * .
 * 开启后台下载服务
 */
public class BackService extends IntentService {

  public static final String ACTION_CACHE = "service.action.cache";
  public static final String LOGIN = "service_action_login";

  private AppApplication mApplication;

  public BackService() {
    super("BackService");
  }

  @Override
  public void onCreate() {
    super.onCreate();
    mApplication = AppApplication.getInstance();
  }

  @Override
  protected void onHandleIntent(Intent intent) {
    if (intent != null) {
      final String action = intent.getAction();
      final Bundle bundle = intent.getExtras();
      if (LOGIN.equals(action)) {
        LoginApiService loginApiService =
            mApplication.getApiServiceComponent().getRetrofit().create(LoginApiService.class);
//        String token= (String) mApplication.getCacheData(ConstanceValue.TOKEN,"");
//        if(!"".equals(token)){//进入登录后页面
//
//        }else {//跳转到登录界面
//          startActivity(new Intent(this, LoginActivity.class));
//        }
        String account=intent.getStringExtra(ConstanceValue.ACCOUNT);
        String password=intent.getStringExtra(ConstanceValue.PASSWORD);
        String captcha=intent.getStringExtra(ConstanceValue.CAPTCHA);
//      Disposable disposable= loginApiService.getLoginInfo(account,password,captcha)
//            .compose(SchedulersCompat.applyIoNoMainSchedulers())
//            .subscribe(new Consumer<Object>() {
//              @Override
//              public void accept(Object o) throws Exception {
//                LoginBean weatherBean = (LoginBean) o;
//
//              }
//            }, new ErrorResultBean() {
//              @Override
//              protected void onError(ErrorResultBean.ErrorBean errorBean) {
//
//              }
//            });
      }

    }

  }


}
